home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / c / MEMLib.lha / MEMLib / Developer / source.org / mempriv.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-30  |  5.6 KB  |  144 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  2. * |_o_o|\\ Copyright (c) 1989, 1990, 1991 The Software Distillery.        *
  3. * |. o.| ||          All Rights Reserved                                  *
  4. * | .  | ||          Written by Doug Walker                               *
  5. * | o  | ||          The Software Distillery                              *
  6. * |  . |//           405 B3 Gooseneck Drive                               *
  7. * ======             Cary, NC 27513                                       *
  8. *                                                                         *
  9. \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  10.  
  11.  
  12.  
  13.  
  14.  
  15. /**************************************************************************/
  16. /**************************************************************************/
  17. /**************************************************************************/
  18. /*                                                                        */
  19. /* DO NOT INCLUDE THIS FILE IN YOUR PROGRAM.  IT IS FOR MEMLIB'S INTERNAL */
  20. /* USE ONLY.  USE THE FILE "memwatch.h" FOR YOUR PROGRAM FILES.           */
  21. /*                                                                        */
  22. /**************************************************************************/
  23. /**************************************************************************/
  24. /**************************************************************************/
  25.  
  26. #ifndef D_MEMPRIV_H
  27. #define D_MEMPRIV_H
  28.  
  29.  
  30. #include <exec/types.h>
  31. #include <exec/memory.h>
  32. #include <exec/ports.h>
  33. #include <proto/exec.h>
  34. #include <proto/dos.h>
  35. #include <string.h>
  36. #include <stdarg.h>
  37.  
  38. #define MWDEBUG 1   /* MWDEBUG is always defined for the library itself */
  39. #include "memwatch.h"
  40.  
  41. #define MW_NEWLINE "\n"    /* echo a newline before each error */
  42.                            /* note that this was defined as "\7\n" in the original */
  43.  
  44. #ifdef AllocMem
  45. #undef AllocMem
  46. #endif
  47.  
  48. #ifdef FreeMem
  49. #undef FreeMem
  50. #endif
  51.  
  52. #define MWT_CHIP 0
  53. #define MWT_FAST 1
  54.  
  55. #define MW_HEADLEN  4  /* Number of bytes for header sentinel */
  56.  
  57. /* The following string must be >= MW_HEADLEN bytes */
  58. #define MWHEADSTR "HEAD"
  59.                  /*0123*/
  60.  
  61. #define MW_TRAILLEN 8  /* Number of bytes for trailer sentinel */
  62.  
  63. /* The following string must be >= MW_TRAILLEN bytes */
  64. #define MWTRAILSTR "\xBB\xBB\xBB\xBB\xBB\xBB\xBB\xBB"
  65.  
  66. struct MWGlobal
  67. {
  68.    LONG flags;          /* Various MWF_ flags, see memwatch.h           */
  69.    LONG num[2];         /* Current number of allocations, chip and fast */
  70.    LONG sum[2];         /* Current amount allocated, chip and fast      */
  71.    LONG max[2];         /* Max amount allocated, chip and fast          */
  72.    LONG lim[2];         /* Limit on allocations, chip and fast          */
  73.    BPTR dbfh;           /* File to send debug output to                 */
  74.    struct MWAlc *first; /* List of active memory allocations            */
  75.    struct MWAlc *freed; /* List of free memory extents                  */
  76.    struct MWAlc *lfree; /* Last allocation freed with free()            */
  77.    struct Task *task;   /* Pointer to owning task's Task structure      */
  78.    char *dbnm;          /* name of debug log file                       */
  79.    int headlen,         /* Length of header sentinel                    */
  80.        traillen;        /* Length of trailer sentinel                   */
  81. };
  82.  
  83. struct MWAlc
  84. {
  85.    struct MWAlc *next;  /* Next memory block in chain           */
  86.    LONG size;           /* Size of allocation in bytes          */
  87.    LONG flags;          /* MEMF_ Flags memory was allocated with*/
  88.    LONG internal;       /* internal flags, see MWI_ defines     */
  89.    char *file;          /* Filename containing allocation point */
  90.    LONG line;           /* Line number of allocation            */
  91.    char *ffile;         /* Filename of free point               */
  92.    long fline;         /* Line number of free point            */
  93.    char header[MW_HEADLEN];     /* Header sentinal              */
  94.    char memory[MW_TRAILLEN+3];  /* Actual allocation comes here */
  95.                         /* extra bytes cover trailer sentinal   */
  96. };
  97.  
  98. /* Defines for use with MWAlc.internal       */
  99. /* if internal&MWI_REPMASK == MWI_REPORTED,  */
  100. /* This alloc already reported as trashed    */
  101. /* Use multiple bits in case 'internal'      */
  102. /* are trashed, odds are better of detecting */
  103. /* If we ever need more myflag bits, just    */
  104. /* define MWI_REPMASK not to include them    */
  105.  
  106. #define MWI_REPORTED 0xaa55aa50
  107. #define MWI_REPMASK  0xfffffff0
  108.  
  109.  
  110. #define MWATRASH     0xaa  /* Trash allocated memory with this           */
  111. #define MWFTRASH     0x55  /* Trash freed memory with this               */
  112.  
  113. void MWHold   (void);
  114. void MWPurge  (void);
  115. void MWPanic  (char *);
  116. void MWPrintf (char *, ...);
  117. int MWCheckA  (struct MWAlc *);
  118.  
  119. /* If you want debugging to use the serial port, you must have */
  120. /* Commodore's debug.lib.  If you do, change the #define below */
  121. /* to a 1 and add debug.lib to your link line.                 */
  122. #define USEDEBUGLIB 0
  123. #if USEDEBUGLIB
  124. /* Defined in Commodore's debug.lib */
  125. void __stdargs KPutStr(char *string);
  126. #else
  127. #define KPutStr(x)
  128. #endif
  129.  
  130. #define MWPrintAlc(mwa) \
  131.    {MWPrintf("0x%08lx length %ld allocated line %ld file \"%s\"\n", \
  132.             (mwa)->memory, (mwa)->size, (mwa)->line, (mwa)->file); \
  133.     if((mwa)->ffile) MWPrintf("Freed line %ld file \"%s\"\n", \
  134.        (mwa)->fline, (mwa)->ffile);}
  135.  
  136. #define ALCFAMILY(x) ((x) & MWI_MALLOC ? "malloc"    : \
  137.                       (x) & MWI_VEC    ? "AllocVec"  : "AllocMem")
  138.  
  139. #define FREFAMILY(x) ((x) & MWI_MALLOC ? "free"     : \
  140.                       (x) & MWI_VEC    ? "FreeVec"  : "FreeMem")
  141.  
  142. #endif /* D_MEMPRIV_H */
  143.  
  144.